package com.yunhe.policyfulfillment.policyful.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.policyful.domain.PolicyInfoNews;
import com.yunhe.policyfulfillment.policyful.model.NewStauts;
import com.yunhe.policyfulfillment.policyful.model.PolicyInfoNewsQueryCondition;
import com.yunhe.policyfulfillment.policyful.model.PublishStatus;
import com.yunhe.policyfulfillment.policyful.service.PolicyInfoNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassName PolicyInfoNewsController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/23 16:47
 * @Version 1.0
 **/
@Api(value = "PolicyInfoNews", description = "新闻维护", tags = {"Model_PolicyInfoNews"})
@RestController
@RequestMapping(value = "/policyInfoNews")
public class PolicyInfoNewsController {

    @Autowired
    private PolicyInfoNewsService policyInfoNewsService;

    /**
     * 新增
     * @date 2021/07/23
     **/
    @ApiOperation("新增新闻")
    @PostMapping("/createPolicyInfoNews")
    public ResponseEntity<ResultObject<Integer>> createPolicyInfoNews(@RequestBody  PolicyInfoNews policyInfoNews) throws ArgumentErrorException {
        return new ResponseEntity<>(new ResultObject(policyInfoNewsService.createPolicyInfoNews(policyInfoNews)), HttpStatus.OK);
    }

    /**
     * 刪除
     * @date 2021/07/23
     **/
    @ApiOperation("刪除新闻")
    @DeleteMapping("/deletePolicyInfoNewsById")
    public ResponseEntity<ResultObject<Integer>> deletePolicyInfoNewsById(@RequestParam(value = "id",required = true) long id){
        return new ResponseEntity<>(new ResultObject(policyInfoNewsService.deletePolicyInfoNewsById(id)),HttpStatus.OK);
    }

    /**
     * 更新
     * @date 2021/07/23
     **/
    @ApiOperation("更新新闻")
    @PostMapping("/updatePolicyInfoNews")
    public ResponseEntity<ResultObject<Integer>> updatePolicyInfoNews(@RequestBody PolicyInfoNews policyInfoNews){
        return new ResponseEntity<>(new ResultObject(policyInfoNewsService.updatePolicyInfoNews(policyInfoNews)),HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @date 2021/07/23
     **/
    @ApiOperation("查询 新闻")
    @GetMapping("/findPolicyInfoNewsById")
    public ResponseEntity<ResultObject<PolicyInfoNews>> findPolicyInfoNewsById(@RequestParam(value = "id",required = true) long id){
        return new ResponseEntity<>(new ResultObject(policyInfoNewsService.findPolicyInfoNewsById(id)),HttpStatus.OK);
    }

    /**
     * 查询 分页查询
     * @date 2021/07/23
     **/
    @ApiOperation("分页查询")
    @PostMapping("/findPolicyInfoNewsByQueryCondition")
    public ResponseEntity<ResultObject<List<PolicyInfoNews>>> findPolicyInfoNewsByQueryCondition(@RequestBody PolicyInfoNewsQueryCondition policyInfoNewsQueryCondition) throws ArgumentErrorException {
         PageResult pageResult = policyInfoNewsService.findPolicyInfoNewsByQueryCondition(policyInfoNewsQueryCondition);
        return new ResponseEntity<>( new ResultObject(pageResult),HttpStatus.OK);
    }

    /**
     * 设置置顶
     * @date 2021/07/23
     **/
    @ApiOperation("设置置顶")
    @PostMapping("/setTop")
    public ResponseEntity<ResultObject<Void>> setTop(@RequestParam(value = "id",required = true) long id) throws ArgumentErrorException {
        policyInfoNewsService.setTop(id);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    /**
     * 设置热门
     * @date 2021/07/23
     **/
    @ApiOperation("设置热门")
    @PostMapping("/setHot")
    public ResponseEntity<ResultObject> setHot(@RequestBody NewStauts newStauts) throws ArgumentErrorException {
        policyInfoNewsService.setHot(newStauts);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    /**
     * 设置new
     * @date 2021/07/23
     **/
    @ApiOperation("设置new")
    @PostMapping("/setNew")
    public ResponseEntity<ResultObject> setNew(@RequestBody NewStauts newStauts) throws ArgumentErrorException {
        policyInfoNewsService.setNew(newStauts);
        return new ResponseEntity<> (new ResultObject(),HttpStatus.OK);
    }

    /**
     * 设置发布状态
     * @date 2021/07/23
     **/
    @ApiOperation("设置发布状态")
    @PostMapping("/setPublishStatus")
    public ResponseEntity<ResultObject> setPublishStatus(@RequestBody PublishStatus publishStatus) throws ArgumentErrorException {
        policyInfoNewsService.setPublishStatus(publishStatus);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

}